package ibms_rcp.tableViewer;

import ibms_rcp.dao.BillManager;
import ibms_rcp.model.BillLog;
import ibms_rcp.model.Company;
import ibms_rcp.model.Lease;
import ibms_rcp.model.PayLog;
import ibms_rcp.model.RechargeLog;
import ibms_rcp.model.SeqGenereter;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

public class TableLabelProvider extends LabelProvider  implements ITableLabelProvider {
		public String getColumnText(Object element, int columnIndex) {
			//公司查询用到的公司model
			if (element instanceof Company){
				Company com = (Company)element;
				if(columnIndex == 0){
					return com.getCode();
				}else if(columnIndex == 1){
					return com.getName();
				}else if (columnIndex ==2){
					return com.getPer();
				}else if (columnIndex == 3){
					return com.getTel();
				}else if (columnIndex == 4){
					return com.getPhone();
				}else if (columnIndex == 5){
					return Double.toString(com.getBalance());
				}else if (columnIndex == 6){
					return Integer.toString(com.getRemindDay());
				}
			}
			//充值记录查询用到的充值记录model
			else if(element instanceof RechargeLog){
				//int i=0;
				RechargeLog re = (RechargeLog)element;
				if(columnIndex == 0){
					return Integer.toString(SeqGenereter.getseq());//产生递增序号
				}else if(columnIndex == 1){
					return re.getCompany_name();
				}else if (columnIndex ==2){
					return re.getRecharge_time().toString();
				}else if (columnIndex == 3){
					return Double.toString(re.getRecharge_point());
				}else if (columnIndex == 4){
					return Double.toString(re.getPoint());
				}else if (columnIndex == 5){
					return re.getUser_name();
				}
			}
			else if (element instanceof Lease){
				Lease lease = (Lease)element;
				if(columnIndex == 0){
					return Integer.toString(SeqGenereter.getseq());
				}else if(columnIndex == 1){
					return String.valueOf(lease.getBuildingId());
				}else if (columnIndex ==2){
					return String.valueOf(lease.getFloorId());
				}else if (columnIndex == 3){
					return String.valueOf(lease.getRoomId());
				}else if (columnIndex == 4){
					return lease.getFromDate();
				}else if (columnIndex == 5){
					return lease.getToDate();
				}else if (columnIndex == 6){
					return lease.getChargeDate();
				}else if (columnIndex == 7){
					return String.valueOf(lease.isPreCharge());
				}else if (columnIndex == 8){
					return String.valueOf(lease.isPropCharge());
				}else if (columnIndex == 9){
					return String.valueOf(lease.isElecCharge());
				}
			}
			//消费结算用到的消费结算记录model
			else if(element instanceof PayLog){
				PayLog pa = (PayLog)element;
				BillLog bLog = BillManager.getOneBillLogsbybill_id(pa.getBill_id());
				if(bLog.getBill_type().equals("物业费")){
					bLog.setOldvalue("开始:"+bLog.getOldvalue());
					bLog.setNowvalue("截止:"+bLog.getNowvalue());
					bLog.setCostvalue("月个数:"+bLog.getCostvalue());
				}
				if(columnIndex == 0){
					return Integer.toString(SeqGenereter.getseq());
				}else if(columnIndex == 1){
					return pa.getCompany_name();
				}else if (columnIndex ==2){
					return bLog.getBu();
				}else if (columnIndex == 3){
					return bLog.getFl();
				}else if (columnIndex == 4){
					return bLog.getRo();
				}else if (columnIndex == 5){
					return pa.getPay_time().toString();
				}else if (columnIndex ==6){
					return bLog.getBill_type();
				}else if (columnIndex ==7){
					return bLog.getOldvalue();
				}else if (columnIndex ==8){
					return bLog.getNowvalue();
				}else if (columnIndex ==9){
					return bLog.getCostvalue();
				}else if (columnIndex == 10){
					return Double.toString(bLog.getBill_point());
				}else if (columnIndex ==11){
					return Double.toString(pa.getBalance());
				}
			}//账单model
			else if(element instanceof BillLog){
				BillLog bl = (BillLog)element;
				if(bl.getBill_type().equals("物业费")){
					bl.setOldvalue("开始:"+bl.getOldvalue());
					bl.setNowvalue("截止:"+bl.getNowvalue());
					bl.setCostvalue("月个数:"+bl.getCostvalue());
				}
				if(columnIndex == 0){
					return Integer.toString(SeqGenereter.getseq());//生成递增序列
				}else if(columnIndex == 1){
					return bl.getCompany_name();
				}else if (columnIndex ==2){
					return bl.getBu();
				}else if (columnIndex == 3){
					return bl.getFl();
				}else if (columnIndex == 4){
					return bl.getRo();
				}else if (columnIndex == 5){
					return bl.getBilltime().toString();
				}else if (columnIndex ==6){
					return bl.getBill_type();
				}else if (columnIndex == 7){
					return bl.getOldvalue();
				}else if (columnIndex == 8){
					return bl.getNowvalue();
				}else if (columnIndex == 9){
					return bl.getCostvalue();
				}else if (columnIndex == 10){
					return Double.toString(bl.getBill_point());
				}else if (columnIndex == 11){
					String flag = null;
					if(bl.isDealflag()){
						flag = "是";
					}else {
						flag = "否";
					}
					return flag;
				}
			}
			return null;
		}
		public Image getColumnImage(Object element, int columnIndex) {
			return null;
		}
	}